* set path

**# Bookmark #1
	global raw "~/agriculture_temperature"
	
	global temp "~/revision_codes/temp"
	global visual "~/revision_codes/visual"
	
	use $raw/data/merged_for_reg, clear

	xtset ctycode year
	
	
********************************************************************************
* Robustness check:alternative bins widths of 3°C and 10°C
*((Figure A1,A2))
********************************************************************************
***1.bins widths of 3°C
	egen dd3binPos = rowtotal(dd3bin*)
	gen dd3binNeg = 365 -  dd3binPos
	replace dd3binNeg = 0 if dd3binNeg < 0
	drop dd3binPos

* set reference bin

	rename dd3bin9 REF_BIN
	
	tempfile r1 r2 r3 
	
	* ag values - overall
	foreach t in 3 {
		foreach x in aoutput farming_output forest_output livestock_output fishery_output{
			
			 qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & inlist(region3,1,2), ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")

	 esttab all_*_3C using $raw/revision_result/ouput_value_all_counties3C.rtf, replace  b(4) se(4) keep(dd3bin* *pre* *ssd* *rhu* *prs* *win*) star(* 0.10 ** 0.05 *** 0.01) scalar(r2)

			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==1, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store north_`x'_`t'C			
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")
				 esttab north_*_3C using $raw/revision_result/ouput_value_north_3C.rtf, replace  b(4) se(4) keep(dd3bin* *pre* *ssd* *rhu* *prs* *win*) star(* 0.10 ** 0.05 *** 0.01) scalar(r2)

			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==2, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store south_`x'_`t'C	
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	
esttab south_*_3C using $raw/revision_result/ouput_value_south_3C.rtf, replace  b(4) se(4) keep(dd3bin* *pre* *ssd* *rhu* *prs* *win*) star(* 0.10 ** 0.05 *** 0.01) scalar(r2)
	
			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  spec
			save $temp/est_RevAgVal_3C_`x',replace
			restore			
			
			}
		}

		
***2.bins widths of 10°C
* set path

	global raw "~/agriculture_temperature"
	
	global temp "~/revision_codes/temp"
	global visual "~/revision_codes/visual"

	use $raw/data/merged_for_reg, clear

	xtset ctycode year
	

	egen dd10binPos = rowtotal(dd10bin*)
	gen dd10binNeg = 365 -  dd10binPos
	replace dd10binNeg = 0 if dd10binNeg < 0
	drop dd10binPos


* set reference bin

	rename dd10bin0 REF_BIN
	
	tempfile r1 r2 r3 
	
	* ag values - overall
	foreach t in 10 {
		foreach x in aoutput farming_output forest_output livestock_output fishery_output{
			
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & inlist(region3,1,2), ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")

	 esttab all_*_10C using $raw/revision_result/ouput_value_all_counties10C.rtf, replace  b(4) se(4) keep(dd10bin* *pre* *ssd* *rhu* *prs* *win*) star(* 0.10 ** 0.05 *** 0.01) scalar(r2)

			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==1, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store north_`x'_`t'C			
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")
				 esttab north_*_10C using $raw/revision_result/ouput_value_north_10C.rtf, replace  b(4) se(4) keep(dd10bin* *pre* *ssd* *rhu* *prs* *win*) star(* 0.10 ** 0.05 *** 0.01) scalar(r2)

			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==2, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store south_`x'_`t'C	
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	
						 esttab south_*_10C using $raw/revision_result/ouput_value_south_10C.rtf, replace  b(4) se(4) keep(dd10bin* *pre* *ssd* *rhu* *prs* *win*) star(* 0.10 ** 0.05 *** 0.01) scalar(r2)
	
			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  spec
			save $temp/est_RevAgVal_10C_`x',replace
			restore			
			
			}
		}


********************************************************************************
* Robustness check:Alternative Controls
*Figure A3
********************************************************************************
	
	global raw "~/agriculture_temperature"
	
	global temp "~/revision_codes/temp"
	global visual "~/revision_codes/visual"
	
	use $raw/data/merged_for_reg, clear

	xtset ctycode year
	
* drop ref bin

	drop dd5bin10
	
* robustness
	
	* 0. baseline
	
	tempfile r1 r2 r3 
	
	estimates clear
	
	foreach t in 5 {
		foreach x in aoutput farming_output forest_output livestock_output fishery_output{
			
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & inlist(region3,1,2), ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")
				
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==1, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store north_`x'_`t'C			
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")
			
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==2, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store south_`x'_`t'C	
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	
			
			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  region
			gen spec = "Baseline"
			save $temp/est_baseline_`x',replace
			restore			
			
			}
		}	
	
	* 1. no control
	
	tempfile r1 r2 r3 
	
	estimates clear	
	
		foreach t in 5 {
			foreach x in aoutput farming_output forest_output livestock_output fishery_output {
		
		* ag values - overall
		
				qui reghdfe ln_`x' dd`t'bin* ///
						i.pro#c.year##c.year ///
						if inrange(year,1995,2015) & inlist(region3,1,2), ///
						absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")
				
		* ag values in north
				
				qui reghdfe ln_`x' dd`t'bin* ///
						i.pro#c.year##c.year ///
						if inrange(year,1995,2015) & region3==1, ///
						absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store north_`x'_`t'C			
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")
				
		* ag values in south
				
				qui reghdfe ln_`x' dd`t'bin* ///
						i.pro#c.year##c.year ///
						if inrange(year,1995,2015) & region3==2, ///
						absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store south_`x'_`t'C								
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	
			
			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  region
			gen spec = "No weather control"
			save $temp/est_robust1_`x',replace
			restore			
			
			}
		}
		
	
	* 2. only control prec
	
	tempfile r1 r2 r3 
	
	estimates clear	
	
		foreach t in 5 {
			foreach x in aoutput farming_output forest_output livestock_output fishery_output{
				
				
				qui reghdfe ln_`x' dd`t'bin* ///
						c.pre##c.pre  ///
						i.pro#c.year##c.year ///
						if inrange(year,1995,2015) & inlist(region3,1,2), ///
						absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")
				
				qui reghdfe ln_`x' dd`t'bin* ///
						c.pre##c.pre  ///
						i.pro#c.year##c.year ///
						if inrange(year,1995,2015) & region3==1, ///
						absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store north_`x'_`t'C
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")
				
				qui reghdfe ln_`x' dd`t'bin* ///
						c.pre##c.pre  ///
						i.pro#c.year##c.year ///
						if inrange(year,1995,2015) & region3==2, ///
						absorb(ctycode year) cluster(ctycode proXyear) 
				estimates store south_`x'_`t'C
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	

			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  region
			gen spec = "Prec control only"
			save $temp/est_robust2_`x',replace
			restore			
		
				}
			}
			
	
	* 3. no prov trends
	
	tempfile r1 r2 r3 
	
	estimates clear	
	
	foreach t in 5 {
		foreach x in aoutput farming_output forest_output livestock_output fishery_output{
		
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					if inrange(year,1995,2015) & inlist(region3,1,2), ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")
			
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					if inrange(year,1995,2015) & region3==1, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store north_`x'_`t'C
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")

			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					if inrange(year,1995,2015) & region3==2, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store south_`x'_`t'C
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	

			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  region
			gen spec = "No provincial trends"
			save $temp/est_robust3_`x',replace
			restore			
			
			}
		}
		
		
	* 4. linear prov trends	
	
	tempfile r1 r2 r3 
	
	estimates clear	
		
	* ag values - overall
	foreach t in 5 {
		foreach x in aoutput farming_output forest_output livestock_output fishery_output{
			
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year ///
					if inrange(year,1995,2015) & inlist(region3,1,2), ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")
			
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year ///
					if inrange(year,1995,2015) & region3==1, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store north_`x'_`t'C
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")

			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year ///
					if inrange(year,1995,2015) & region3==2, ///
					absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store south_`x'_`t'C
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	

			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  region
			gen spec = "Linear provincial trends"
			save $temp/est_robust4_`x',replace
			restore			
						
			}
		}
		
********************************************************************************
* Robustness check:Alternative clusters
*Figure A4
********************************************************************************
		
	* 5. clustering (cty and year)	
	
	tempfile r1 r2 r3 
	
	estimates clear	
	
	foreach t in 5 {
		foreach x in aoutput farming_output forest_output livestock_output fishery_output{
			
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & inlist(region3,1,2), ///
					absorb(ctycode year) cluster(ctycode year) 
			estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")
			
			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==1, ///
					absorb(ctycode year) cluster(ctycode year) 
			estimates store north_`x'_`t'C
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")

			qui reghdfe ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year ///
					if inrange(year,1995,2015) & region3==2, ///
					absorb(ctycode year) cluster(ctycode year) 
			estimates store south_`x'_`t'C
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	

			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  region
			gen spec = "County & Year"
			save $temp/est_cluster1_`x',replace
			restore			
									
			}
		}
		
	* 6. clustering (prov)	

	foreach t in 5 {
		foreach x in aoutput farming_output forest_output livestock_output fishery_output{
			qui xtreg ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year i.year ///
					if inrange(year,1995,2015) & inlist(region3,1,2), ///
					fe cluster(pro) 
			estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")
			
			qui xtreg ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year i.year ///
					if inrange(year,1995,2015) & inlist(region3,1), ///
					fe cluster(pro) 
			estimates store north_`x'_`t'C
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")

			qui xtreg ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year i.year ///
					if inrange(year,1995,2015) & inlist(region3,2), ///
					fe cluster(pro) 
			estimates store south_`x'_`t'C
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	

			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  region
			gen spec = "Province"
			save $temp/est_cluster2_`x',replace
			restore			
			
			}
		}
		
			
	* 7. clustering (cty)		
	foreach t in 5 {
		foreach x in aoutput farming_output forest_output livestock_output fishery_output{
			
			qui xtreg ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year i.year ///
					if inrange(year,1995,2015) & inlist(region3,1,2), ///
					fe cluster(ctycode) 
			estimates store all_`x'_`t'C
		parmest , label saving(`"`r1'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("All areas")

			qui xtreg ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year i.year ///
					if inrange(year,1995,2015) & inlist(region3,1), ///
					fe cluster(ctycode) 
			estimates store north_`x'_`t'C
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")

			qui xtreg ln_`x' dd`t'bin* ///
					c.pre##c.pre c.ssd##c.ssd c.rhu##c.rhu c.prs##c.prs c.win##c.win ///
					i.pro#c.year##c.year i.year ///
					if inrange(year,1995,2015) & inlist(region3,2), ///
					fe cluster(ctycode) 
			estimates store south_`x'_`t'C
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	

			preserve 
			use `"`r1'"',clear
			append using `"`r2'"' `"`r3'"' 
			gen sector = "`x'"
			rename id  region
			gen spec = "County"
			save $temp/est_cluster3_`x',replace
			restore			
			
			}
		}
		
	********************************************************
	*************** arrange the coefficient ****************
	********************************************************
	
	* different robustness spec
	
	use $temp/est_baseline_aoutput,clear
	foreach file in farming_output forest_output livestock_output fishery_output {
			append using $temp/est_baseline_`file'
			}
	
	foreach file in aoutput farming_output forest_output livestock_output fishery_output {
		foreach spec in robust1 robust2 robust3 robust4 {
			append using $temp/est_`spec'_`file'
			}
		}
		
	// keep temp variables only
	keep if strmatch(parm,"*dd5bin*")
	
	//level varibables
	gen level = 2.5 if strmatch(parm, "dd5bin0")
	replace level = 7.5 if strmatch(parm, "dd5bin5")
	replace level = -2.5 if strmatch(parm, "dd5binNeg")
	*replace level = 12.5 if strmatch(parm, "dd5bin10")
	replace level = 17.5 if strmatch(parm, "dd5bin15")
	replace level = 22.5 if strmatch(parm, "dd5bin20")
	replace level = 27.5 if strmatch(parm, "dd5bin25")
	replace level = 32.5 if strmatch(parm, "dd5bin30")
	replace level = 37.5 if strmatch(parm, "dd5bin35")

	
	// sector name 
	replace sector = "Aggregate" if strmatch(sector,"aoutput")
	replace sector = "Cropping" if strmatch(sector,"farming_output")
	replace sector = "Livestock" if strmatch(sector,"livestock_output")
	replace sector = "Forestry" if strmatch(sector,"forest_output")
	replace sector = "Fishery" if strmatch(sector,"fishery_output")
		
	rename estimate coef 
	rename stderr se 
	rename min95 ci_l
	rename max95 ci_h
	
	// add zero-value lines
	bysort region spec sector : gen last = _n == _N
	expand 2 if last
	sort region spec sector parm
	replace level = 12.5 if parm==parm[_n-1]
	replace coef = 0 if parm==parm[_n-1]
	replace se = 0 if parm==parm[_n-1]
	replace ci_h = 0 if parm==parm[_n-1]
	replace ci_l = 0 if parm==parm[_n-1]	
	
	save $visual/visual_robust_added,replace
	
	* different clustering
	
	use $temp/est_baseline_aoutput,clear
	foreach file in farming_output forest_output livestock_output fishery_output {
			append using $temp/est_baseline_`file'
			}
	
	foreach file in aoutput farming_output forest_output livestock_output fishery_output {
		foreach spec in cluster1 cluster2 cluster3 {
			append using $temp/est_`spec'_`file'
			}
		}
		
	// keep temp variables only
	keep if strmatch(parm,"*dd5bin*")
	
	//level varibables
	gen level = 2.5 if strmatch(parm, "dd5bin0")
	replace level = 7.5 if strmatch(parm, "dd5bin5")
	replace level = -2.5 if strmatch(parm, "dd5binNeg")
	*replace level = 12.5 if strmatch(parm, "dd5bin10")
	replace level = 17.5 if strmatch(parm, "dd5bin15")
	replace level = 22.5 if strmatch(parm, "dd5bin20")
	replace level = 27.5 if strmatch(parm, "dd5bin25")
	replace level = 32.5 if strmatch(parm, "dd5bin30")
	replace level = 37.5 if strmatch(parm, "dd5bin35")

	
	// sector name 
	replace sector = "Aggregate" if strmatch(sector,"aoutput")
	replace sector = "Cropping" if strmatch(sector,"farming_output")
	replace sector = "Livestock" if strmatch(sector,"livestock_output")
	replace sector = "Forestry" if strmatch(sector,"forest_output")
	replace sector = "Fishery" if strmatch(sector,"fishery_output")
		
	rename estimate coef 
	rename stderr se 
	rename min95 ci_l
	rename max95 ci_h
	
	// add zero-value lines
	bysort region spec sector : gen last = _n == _N
	expand 2 if last
	sort region spec sector parm
	replace level = 12.5 if parm==parm[_n-1]
	replace coef = 0 if parm==parm[_n-1]
	replace se = 0 if parm==parm[_n-1]
	replace ci_h = 0 if parm==parm[_n-1]
	replace ci_l = 0 if parm==parm[_n-1]	
	
	save $visual/visual_clusters,replace	
	
	
	// delete dta data 
	cd $temp/
	fs *.dta
	foreach f in `r(files)'{
	   erase "`f'"
	}
						
		
		